package com.example.demo.testTwo;

import cn.hutool.core.bean.BeanUtil;
import com.example.demo.Util.ListHandleUtil;
import com.example.demo.testTwo.dto.PushDTO;

import java.util.ArrayList;
import org.apache.commons.collections4.ListUtils;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * @description
 *
 * @author lilinchun
 * @date 2024/03/26
 */
public class TestFour {

    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();

        // 使用Random类生成随机数
        Random random = new Random();
        for (int i = 0; i < 500; i++) {
            list.add(random.nextInt(1000)) ; // 生成0~99的随机数
        }
        List<Integer> collect = list.stream().distinct().collect(Collectors.toList());
        System.out.println(collect.size());
        PushDTO pushDTO = new PushDTO();
        pushDTO.setTitle("测试").setTargets(collect);
        //判断目标用户个数（环信超过100人不能发送成功）
        List<List<Integer>> splitList = ListUtils.partition(pushDTO.getTargets(), 100);
        splitList.forEach(x -> {
            PushDTO packDTO=new PushDTO();
            BeanUtil.copyProperties(pushDTO,packDTO);
            packDTO.setTargets(x);
            try {
                getMsg(packDTO);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }


    public static void getMsg(PushDTO pushDTO) throws InterruptedException {
        System.out.println("11111111111"+pushDTO.toString());
        Thread.sleep(1000);
    }
}
